﻿using System;
using System.Threading;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;


namespace MonitorFileConvert
{
    public class Tools
    {

        /// <summary>
        /// 调用exe执行相应操作
        /// </summary>
        /// <param name="stringPath">exe所在路径（如:E:\ttt\**.exe）</param>
        /// <param name="stringArguments">给exe传递的参数</param>
        /// <returns></returns>
        public static bool CreateProcess(string stringPath, string stringArguments, bool boolShowDosWindow)
        {
            if (!System.IO.File.Exists(stringPath))
            {
                throw new Exception("未找到EXE文件！");
                return false;

            }
            try
            {
                ProcessStartInfo info3 = new ProcessStartInfo(stringPath);
                if (boolShowDosWindow)
                    info3.WindowStyle = ProcessWindowStyle.Normal;
                else
                    info3.WindowStyle = ProcessWindowStyle.Hidden;

                info3.Arguments = stringArguments;

                Process proc = new Process();
                proc = Process.Start(info3);

                proc.WaitForExit();

                proc.Close();

                return true;
            }
            catch
            {
                throw;
                return false;
            }
        }


        #region 获取config中设置的参数
        /// <summary>
        /// 获取config中的AppSettings参数
        /// </summary>
        /// <param name="strKey"></param>
        /// <param name="strDefault"></param>
        /// <returns></returns>
        public static string GetAppSetting(string strKey, string strDefault)
        {
            if (System.Configuration.ConfigurationManager.AppSettings[strKey] == null)
            {
                return strDefault;
            }
            else
            {
                return System.Configuration.ConfigurationManager.AppSettings[strKey].ToString();
            }
        }

        /// <summary>
        /// 获取config中的ConnectionSettings参数
        /// </summary>
        /// <param name="strKey"></param>
        /// <param name="strDefault"></param>
        /// <returns></returns>
        public static string GetConnectionSetting(string strKey, string strDefault)
        {
            if (System.Configuration.ConfigurationManager.ConnectionStrings[strKey] == null)
            {
                return strDefault;
            }
            else
            {
                return System.Configuration.ConfigurationManager.ConnectionStrings[strKey].ConnectionString;
            }
        }

        #endregion



    }
}
